WPS Office.apk(点击下载) / CmtCustDatasWriter.java


package cn.wps.moffice.writer.io.customdata.comment;

import com.iflytek.cloud.SpeechEvent;
import com.mopub.mobileads.VastIconXmlManager;
import defpackage.msj;
import defpackage.msm;
import defpackage.msx;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.UUID;

public class CmtCustDatasWriter implements oat {
    private static final String TAG = null;
    private mdl oPx;
    private msm pDU;
    private msx pDV;
    private HashMap<Integer, ArrayList<String>> pDW;
    private int pDX;

    public CmtCustDatasWriter(mdl mdl) {
        if (mdl.getType() == 0) {
            this.oPx = mdl;
            this.pDV = this.oPx.dEd();
            this.pDU = this.oPx.dEp();
        }
        this.pDW = new HashMap<>();
        this.pDX = 0;
    }

    private static byte[] KU(String str) {
        try {
            byte[] bArr = new byte[4096];
            FileInputStream fileInputStream = new FileInputStream(str);
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            while (true) {
                int read = fileInputStream.read(bArr);
                if (read > 0) {
                    byteArrayOutputStream.write(bArr, 0, read);
                } else {
                    fileInputStream.close();
                    byteArrayOutputStream.close();
                    return byteArrayOutputStream.toByteArray();
                }
            }
        } catch (IOException e) {
            hm.d(TAG, "FileNotFoundException", e);
            return null;
        }
    }

    private void a(int i, Integer num, String str) {
        ArrayList<String> arrayList = this.pDW.get(Integer.valueOf(i));
        if (arrayList == null) {
            arrayList = new ArrayList<>();
        }
        if (num == null) {
            arrayList.add(str);
        } else {
            arrayList.add(num.intValue(), str);
        }
        this.pDW.put(Integer.valueOf(i), arrayList);
    }

    private boolean c(OutputStream outputStream) {
        if (outputStream == null) {
            return false;
        }
        if (this.oPx == null) {
            return false;
        }
        msm dEp = this.oPx.dEp();
        if (dEp == null || dEp.mSize == 0) {
            return false;
        }
        odo odo = new odo(outputStream);
        odo.i("mcd:customData", "xmlns", "http://www.wps.cn/android/officeDocument/2013/mofficeCustomData", "xmlns:mcd", "http://www.wps.cn/android/officeDocument/2013/mofficeCustomData", "version", "2");
        odo.i("mcd:comments", new String[0]);
        msj.g dOv = this.pDU.dOv();
        while (dOv.hasNext()) {
            try {
                msm.d dVar = (msm.d) dOv.dOx();
                msm.d.a aVar = dVar.pjF;
                if (aVar != null) {
                    StringBuilder sb = new StringBuilder("_mcd_r_");
                    int i = this.pDX;
                    this.pDX = i + 1;
                    String sb2 = sb.append(i).toString();
                    a(this.pDU.b((akm) dVar), null, sb2);
                    odo.i("mcd:comment", "id", sb2);
                    if (aVar.pjH != null) {
                        msx.a QK = this.pDV.QK(aVar.pjH.intValue());
                        StringBuilder sb3 = new StringBuilder("_mcd_s_");
                        int i2 = this.pDX;
                        this.pDX = i2 + 1;
                        String sb4 = sb3.append(i2).toString();
                        a(QK.position(), null, sb4);
                        odo.i("mcd:anchorShape", "id", sb4);
                        odo.i("mcd:pos", "x", new StringBuilder().append(aVar.x).toString(), "y", new StringBuilder().append(aVar.y).toString(), "offsetX", new StringBuilder().append(aVar.jzH).toString(), "offsetY", new StringBuilder().append(aVar.jzG).toString());
                        odo.endElement("mcd:pos");
                        odo.endElement("mcd:anchorShape");
                    }
                    odo.j("mcd:offset", "x", String.valueOf(aVar.jzH), "y", String.valueOf(aVar.jzG));
                    if (0 != aVar.pjJ) {
                        odo.i("mcd:audio", VastIconXmlManager.DURATION, String.valueOf(aVar.pjJ));
                        odo.endElement("mcd:audio");
                    }
                    String a = nfc.a(dVar, this.oPx);
                    if (a != null) {
                        odo.j("mcd:hashCode", SpeechEvent.KEY_EVENT_RECORD_DATA, a);
                    }
                    if (aVar.pjI != null) {
                        String cw = this.oPx.dDV().dIf().cw(aVar.pjI.intValue(), ewg.fnq);
                        ltm ltm = new ltm();
                        byte[] KU = KU(cw);
                        String encode = KU == null ? null : ltm.encode(KU);
                        if (encode != null) {
                            odo.i("mcd:usrIcon", SpeechEvent.KEY_EVENT_RECORD_DATA, encode);
                            odo.endElement("mcd:usrIcon");
                        }
                    }
                    odo.endElement("mcd:comment");
                }
            } catch (mgp e) {
            }
        }
        odo.endElement("mcd:comments");
        odo.endElement("mcd:customData");
        odo.close();
        if (this.pDW.size() > 0) {
            a(0, 0, "_mcd_v_2");
        }
        return true;
    }

    @Override // defpackage.oat
    public final boolean KT(String str) {
        FileOutputStream fileOutputStream;
        try {
            fileOutputStream = new FileOutputStream(str);
        } catch (FileNotFoundException e) {
            hm.d(TAG, "FileNotFoundException", e);
            fileOutputStream = null;
        }
        return c(fileOutputStream);
    }

    @Override // defpackage.oat
    public final boolean KV(String str) {
        FileOutputStream fileOutputStream;
        try {
            fileOutputStream = new FileOutputStream(str);
        } catch (FileNotFoundException e) {
            hm.d(TAG, "FileNotFoundException", e);
            fileOutputStream = null;
        }
        if (fileOutputStream == null || this.oPx == null) {
            return false;
        }
        odo odo = new odo(fileOutputStream);
        odo.i("ds:datastoreItem", "ds:itemID", "{" + UUID.randomUUID() + "}", "xmlns:ds", "http://schemas.openxmlformats.org/officeDocument/2006/customXml");
        odo.i("ds:schemaRefs", new String[0]);
        odo.i("ds:schemaRef", "ds:uri", "http://www.wps.cn/android/officeDocument/2013/mofficeCustomData");
        odo.endElement("ds:schemaRef");
        odo.endElement("ds:schemaRefs");
        odo.endElement("ds:datastoreItem");
        odo.close();
        return true;
    }

    @Override // defpackage.oat
    public final HashMap<Integer, ArrayList<String>> dUw() {
        return this.pDW;
    }
}